import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/common/app.dart';
import 'package:flutter_smart_heating/pages/user/broadcast/model/broadcast_item_data.dart';
import 'package:flutter_smart_heating/ui/ui.dart';

class BroadcastItemView extends StatelessWidget {
  const BroadcastItemView({
    super.key,
    required this.item,
    this.margin,
    this.onTap,
  });
  final BroadcastItemData item;
  final EdgeInsetsGeometry? margin;
  final Function(BroadcastItemData)? onTap;
  @override
  Widget build(BuildContext context) {
    return UiTap(
      onTap: () {
        onTap?.call(item);
        App.push(item.url.toString());
      },
      child: UiPanel(
        margin: const EdgeInsets.only(
          left: UiTheme.spacingX,
          right: UiTheme.spacingX,
          top: UiTheme.spacingX,
        ),
        padding: const EdgeInsets.all(UiTheme.spacingX),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(children: [
              if (item.isRead == false)
                Container(
                  width: 10,
                  height: 10,
                  margin: const EdgeInsets.only(right: 10),
                  decoration: BoxDecoration(
                    color: UiTheme.primary,
                    borderRadius: BorderRadius.circular(5),
                  ),
                ),
              Expanded(
                child: Text(
                  item.title.toString(),
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    fontSize: UiTheme.fontSize.title,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              const SizedBox(width: 10),
              const Icon(
                Icons.arrow_forward_ios,
                size: 16,
                color: Colors.grey,
              )
            ]),
            const Divider(height: 30),
            Text(
              item.intro.toString(),
              maxLines: 3,
              overflow: TextOverflow.ellipsis,
            ),
            const SizedBox(height: 10),
            Row(
              children: [
                const UiIcon(
                  UiIcons.time_circle,
                  size: 16,
                  color: Colors.grey,
                ),
                const SizedBox(width: 5),
                Text(
                  item.createTime.toString(),
                  style: const TextStyle(
                    color: Colors.grey,
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
